package org.leiyang.entries;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

/**
 * 小文件元信息
 */
@Data
@AllArgsConstructor
@Builder
public class BlockFileMetaInfo implements Comparable<BlockFileMetaInfo> {

    private Integer minId;

    private Integer maxId;

    private String fileName;

    /**
     * 判断id是否属于当前分片文件内
     */
    public Boolean contains(Integer id) {
        return id >= this.minId && id <= this.maxId;
    }

    @Override
    public int compareTo(BlockFileMetaInfo o) {
        return Integer.compare(this.maxId, o.getMinId());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        BlockFileMetaInfo that = (BlockFileMetaInfo) o;
        return minId.equals(that.getMinId()) &&
                maxId.equals(that.getMaxId()) &&
                fileName.equals(that.getFileName());
    }

    @Override
    public int hashCode() {
        return (minId << 20) | maxId;
    }

}
